package com.gengzp.system.controller;

import com.gengzp.common.annotations.OperationLogIgnore;
import com.gengzp.common.model.generic.req.SearchByIdReq;
import com.gengzp.common.model.generic.resp.Result;
import com.gengzp.common.model.pagination.resp.PaginationResponse;
import com.gengzp.common.model.serviceGovernance.req.CreateServiceGovernanceReq;
import com.gengzp.common.model.serviceGovernance.req.EditServiceGovernanceReq;
import com.gengzp.common.model.serviceGovernance.req.PageServiceGovernanceReq;
import com.gengzp.common.model.serviceGovernance.resp.PageServiceGovernanceResp;
import com.gengzp.common.model.serviceGovernance.resp.SearchServiceGovernanceResp;
import com.gengzp.permission.annotation.CheckPermission;
import com.gengzp.system.service.ServiceGovernanceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ClassName ServiceGovernanceController
 * @Description 服务治理模块控制层
 * @Author gengzp
 * @Date 2025/10/13 18:00
 */
@RestController
@RequestMapping("/service_governance")
@Api(tags = "服务治理模块")
public class ServiceGovernanceController {

    @Autowired
    private ServiceGovernanceService serviceGovernanceService;

    /**
     * 创建一条服务治理信息
     */
    @PostMapping("/create")
    @ApiOperation("创建一条服务治理信息")
    @CheckPermission("service_governance:write:create")
    public Result<Void> createServiceGovernance(@Valid @RequestBody CreateServiceGovernanceReq req) {
        serviceGovernanceService.createServiceGovernance(req);
        return Result.getSuccessResult();
    }

    /**
     * 根据id编辑服务治理信息
     */
    @PostMapping("/edit_by_id")
    @ApiOperation("根据id编辑服务治理信息")
    @CheckPermission("service_governance:write:edit")
    public Result<Void> editServiceGovernanceById(@Valid @RequestBody EditServiceGovernanceReq req) {
        serviceGovernanceService.editServiceGovernanceById(req);
        return Result.getSuccessResult();
    }

    /**
     * 根据id删除服务治理信息
     */
    @PostMapping("/remove_by_id")
    @ApiOperation("根据id删除服务治理信息")
    @CheckPermission("service_governance:write:remove")
    public Result<Void> removeServiceGovernanceById(@Valid @RequestBody SearchByIdReq req) {
        serviceGovernanceService.removeServiceGovernanceById(Long.valueOf(req.getId()));
        return Result.getSuccessResult();
    }

    /**
     * 分页查询服务治理信息
     */
    @OperationLogIgnore
    @PostMapping("/page")
    @ApiOperation("分页查询服务治理信息")
    @CheckPermission("service_governance:read")
    public Result<PaginationResponse<PageServiceGovernanceResp>> pageQueryServiceGovernance(@Valid @RequestBody PageServiceGovernanceReq req) {
        return Result.getSuccessResult(serviceGovernanceService.pageQueryServiceGovernance(req));
    }

    /**
     * 根据id查询服务治理信息详情
     */
    @OperationLogIgnore
    @PostMapping("/search_by_id")
    @ApiOperation("根据id查询服务治理信息详情")
    @CheckPermission("service_governance:read")
    public Result<SearchServiceGovernanceResp> searchServiceGovernanceRespById(@Valid @RequestBody SearchByIdReq req) {
        return Result.getSuccessResult(serviceGovernanceService.searchServiceGovernanceById(Long.valueOf(req.getId())));
    }

}
